#pragma once

#include"Protocol.hpp"
#include<iostream>

class Calculate
{
public:
    Calculate(){}
    ~Calculate(){}
    //处理任务
    Responce Exec(Request& req)
    {
        Responce resp;
        //判断操作符进行计算
        switch (req.Oper())
        {
            case '+':
                resp.SetResult(req.X() + req.Y());
                break;
            case '-':
                resp.SetResult(req.X() - req.Y());
                break;
            case '*':
                resp.SetResult(req.X()*req.Y());
                break;
            case '/':
            {
                //判断除数 y 是否为0，来填写_code
                if(req.Y()==0)
                {
                    resp.SetCode(1);
                }
                else
                {
                    resp.SetResult(req.X()/req.Y());
                }
            }
            break;
            case '%':
            {
                //取模的_y 也不能为0
                if(req.Y()==0)
                {
                    resp.SetCode(2);
                }
                else
                {
                    resp.SetResult(req.X()%req.Y());
                }
            }
            break;
            default:
                resp.SetCode(3);
                break;
        }
        return resp;
    }
};